<?php
namespace Admin\Controller;
use Think\Controller;
use Com\WechatAuth;

class MenuController extends Controller {
	protected function _initialize()
	{
		$settings = F('settings') ? F('settings') : M('Settings')->getField('name,value');
		C('settings', $settings);
	}
    public function index(){
    
		$wechat=new WechatAuth(C('settings.weixin_AppID'),C('settings.weixin_AppSecret'),C('settings.weixin_Token'));
		$data=$wechat->menuGet();
		var_dump($data);
    }
    
    public function createmenu(){
    	
    		$sep = DIRECTORY_SEPARATOR;
    		
		 /* 计算问卷链接地址 */
            $host = C('settings.weixin_domain');
            $appID = C('settings.weixin_AppID');
            $redirectURL = "http://weshuoke.com/index.php/home/Index/index";
            $redirectURL = urlencode($redirectURL);
            $link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appID}&redirect_uri={$redirectURL}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    		
             $redirectURL1 = "http://weshuoke.com/index.php/home/Index/equestionnaire";
            $redirectURL1 = urlencode($redirectURL1);
            $link1 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appID}&redirect_uri={$redirectURL1}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    	
              $redirectURL2 = "http://weshuoke.com/index.php/home/Index/coupon";
            $redirectURL2 = urlencode($redirectURL2);
            $link2 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appID}&redirect_uri={$redirectURL2}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    	
            
               $redirectURL3 = "http://weshuoke.com/index.php/home/Index/mine";
            $redirectURL3 = urlencode($redirectURL3);
            $link3 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appID}&redirect_uri={$redirectURL3}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    	
            
              $redirectURL4 = "http://weshuoke.com/index.php/home/index/post";
            $redirectURL4 = urlencode($redirectURL4);
            $link4 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appID}&redirect_uri={$redirectURL4}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    	
    	
    	
     $data= array(
     0=>array(                                                                                  
     "name"=>"微评",
           "sub_button"=>array(
           	0=>array(
               "type"=>"view",
               "name"=>"问卷",
               "url"=>$link1
            ),
            1=>array(
             "type"=>"view",
               "name"=>"优惠券",
               "url"=>$link2
            )
            )
     ),
     1=>array(                                                                                  
     "name"=>"说客",
           "sub_button"=>array(
           	0=>array(
               "type"=>"view",
               "name"=>"首页",
               "url"=>$link
            ),
            1=>array(
             "type"=>"view",
               "name"=>"我的微说",
               "url"=>$link3
            ),
             2=>array(
             "type"=>"view",
               "name"=>"发布话题",
               "url"=>$link4
            )
            
            )   
            )                                                      
     );    
     	$wechat=new WechatAuth(C('settings.weixin_AppID'),C('settings.weixin_AppSecret'),C('settings.weixin_Token'));
     	$result=$wechat->menuCreate($data);
     	var_dump($result);
     
    }
}